<template>
	<view class="box">
		<view class="content">
			<view class="flex_wrap row_center">
				<u-image
					src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/25/c61f6633bd394bfba8c1ab7c545a3dee.png"
					width="124rpx" height="124rpx" mode="widthFix" />
			</view>
			<view>
				<u-text :text="title" size="56rpx" color="#FF3C3C" align="center" margin="42rpx 0 18rpx" />
				<u-text :text="number+'张'" size="28rpx" color="#666" align="center" margin="16rpx 0 48rpx" />
			</view>
			<view class="">
				<u-button
					v-if="!btnType"
					text="发送"
					shape="circle"
					border="none"
					color="linear-gradient(90deg, #FF6E45 0%, #FE5037 100%)"
					openType="share"
				/>
				<u-button
					v-if="btnType"
					:text="receivShow ? '立即领取' : '进入'"
					@click="receivShow ? receive() : toCoupon()"
					shape="circle"
					border="none"
					color="linear-gradient(90deg, #FF6E45 0%, #FE5037 100%)"
				/>
			</view>
		</view>
	</view>
</template>

<script>
	import { favorableDetail,transfer,createActivity,joinActivity } from "@/api/coupon.js";
	export default {
		data() {
			return {
				title: '',
				cardTypeId: '',
				number: '',
				type: '',
				cardActivityUniqueld: '',
				btnType:'',
				receivShow:true,
			};
		},
		onLoad(options) {
			console.log(options)
			this.title = options.title
			this.cardTypeId = options.cardTypeId
			this.number = options.number
			this.type = options.type
			this.cardActivityUniqueld = options.cardActivityUniqueld || ''
			this.btnType = options.btnType || ''
			
		},
		methods: {
			receive(){
				joinActivity({uniqueId:this.cardActivityUniqueld,number:this.number}).then((res) => {
					if(res.code == 200){
						uni.$u.toast('领取成功！')
						this.receivShow = false
					}else{
						this.receivShow = false
						uni.$u.toast(res.data.msg)
						console.log(this.receivShow,'this.receivShow>>')
					}
				});
			},
			toCoupon(){
				uni.reLaunch({
					url: "/pages/counselling/index"
				})
			},
			//发送给朋友
			async onShareAppMessage(res) {
				await createActivity({
				   favorableId: this.cardTypeId,
				   number: this.number,
				   type: this.type,
				   cardPackType:2
				})
				    .then(async (res) => {
				        this.cardActivityUniqueld  = res.data.uniqueId 
						console.log(res,this.cardActivityUniqueld )
				    })
				    .catch((error) => {
				        uni.$u.toast(error);
				    });
				return {
				    title: "HI!我向您赠送了一份礼包！快去领取吧~",
				    path:
				        "/pages_benefitCard/card_management/shareDetail?cardActivityUniqueld=" +this.cardActivityUniqueld+
                    "&number=" +
                    this.number+
                    "&title=" +
                    this.title +
					"&btnType="+true
				};
				console.log(path,'this.path>>>')
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #1E2137;
	}

	.box {
		padding: 32rpx 28rpx;
	}

	.content {
		background: #fff;
		width: 100%;
		border-radius: 12rpx;
		padding: 64rpx 48rpx ;
	}
	
</style>